package com.th.supcom.pds.phamapply.client.widget.phamapplydetail;

import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;

/**
 * InpPhamApplyDetail主面板.
 * 
 * 住院摆药请领明细.
 */
public class InpPhamApplyDetailMainPanel extends LayoutContainer
{

    private PhamApplyButtons m_buttons;
    private PhamApplyFields m_fields;
    private PhamApplyAction m_ations;
    private PhamApplyCurrentApplyGrid m_currentReceiveGrid;
    private PhamApplyDispenseConditionMain m_dispenseConditionMain;
    private PhamApplyCollectGrid m_phamApplyCollectGrid;
    private PhamApplyDetailGrid m_phamApplyDetailGrid;
    private PhamApplyOffsetGrid m_drugReturnGrid;
    private PhamApplyPatientDispenseInfoGrid m_patientDispenseInfoGrid;
    private PhamApplyTabPanel m_phamApplyTabPanel;

    public InpPhamApplyDetailMainPanel ()
    {
        initUI ();
        initAction ();
        initListeners ();
        initData ();
    }

    /**
     * 初始化事件
     */
    private void initAction ()
    {
        m_ations = new PhamApplyAction ();
        m_ations.setphamapplyFields (m_fields);
        m_ations.setApplyDetailGrid (m_phamApplyDetailGrid);
        m_ations.setApplyCollectGrid (m_phamApplyCollectGrid);
        m_ations.setApplyPatientDispenseInfoGrid (m_patientDispenseInfoGrid);
        m_ations.setApplyCurrentApplyGrid (m_currentReceiveGrid);
        m_ations.setApplyOffsetGrid (m_drugReturnGrid);
    }

    /**
     * 初始化数据
     */
    private void initData ()
    {
        m_ations.initData ();
    }

    /**
     * 初始化事件监听
     */
    private void initListeners ()
    {
        PhamApplyListener m_phamApplyListener;
        m_phamApplyListener = new PhamApplyListener ();
        m_phamApplyListener.setphamapplyAction (m_ations);
        m_phamApplyListener.setphamapplyButtons (m_buttons);
        m_phamApplyListener.setphamapplyFields (m_fields);
        m_phamApplyListener.initListeners ();
    }

    /**
     * 初始化UI
     */
    private void initUI ()
    {
        this.setLayout (new BorderLayout ());

        createButtons ();
        createFields ();
        createGrids ();
        createPanels ();

        BorderLayoutData centerData = new BorderLayoutData (LayoutRegion.CENTER);
        centerData.setMargins (new Margins (2, 0, 2, 0));
        BorderLayoutData westData = new BorderLayoutData (LayoutRegion.WEST, 200);
        westData.setMargins (new Margins (2, 5, 2, 0));

        add (m_phamApplyTabPanel, centerData);
        add (m_dispenseConditionMain, westData);
    }

    /**
     * 初始化Buttons
     */
    private void createButtons ()
    {
        m_buttons = new PhamApplyButtons ();
    }

    /**
     * 初始化Fields
     */
    private void createFields ()
    {
        m_fields = new PhamApplyFields ();
    }

    /**
     * 初始化Panel
     */
    private void createPanels ()
    {
        PhamApplyDispenseConditionForm m_dispenseConditionForm;
        m_dispenseConditionForm = new PhamApplyDispenseConditionForm ();
        m_dispenseConditionForm.setPhamApplyButtons (m_buttons);
        m_dispenseConditionForm.setPhamApplyFields (m_fields);
        m_dispenseConditionForm.initUI ();

        m_dispenseConditionMain = new PhamApplyDispenseConditionMain ();
        m_dispenseConditionMain.setDispenseConditionForm (m_dispenseConditionForm);
        m_dispenseConditionMain.setPatientDispenseInfoGrid (m_patientDispenseInfoGrid);
        m_dispenseConditionMain.initUI ();

        PhamApplyDrugOffsetAdjustMainGrid m_drugOffsetAdjustMainGrid;
        m_drugOffsetAdjustMainGrid = new PhamApplyDrugOffsetAdjustMainGrid ();
        m_drugOffsetAdjustMainGrid.setDrugReturnGrid (m_drugReturnGrid);
        m_drugOffsetAdjustMainGrid.setCurrentReceiveGrid (m_currentReceiveGrid);
        m_drugOffsetAdjustMainGrid.initUI ();

        m_phamApplyTabPanel = new PhamApplyTabPanel ();
        m_phamApplyTabPanel.setDrugOffsetAdjustMainGrid (m_drugOffsetAdjustMainGrid);
        m_phamApplyTabPanel.setPhamApplyButtons (m_buttons);
        m_phamApplyTabPanel.setPhamApplyCollectGrid (m_phamApplyCollectGrid);
        m_phamApplyTabPanel.setPhamApplyDetailGrid (m_phamApplyDetailGrid);
        m_phamApplyTabPanel.initUI ();
    }

    /**
     * 初始化Grid
     */
    private void createGrids ()
    {
        m_currentReceiveGrid = new PhamApplyCurrentApplyGrid ();
        m_phamApplyCollectGrid = new PhamApplyCollectGrid ();
        m_phamApplyDetailGrid = new PhamApplyDetailGrid ();
        m_drugReturnGrid = new PhamApplyOffsetGrid ();
        m_patientDispenseInfoGrid = new PhamApplyPatientDispenseInfoGrid ();
    }

    /** 公司版权信息. */
    public static final String copyright = "Copyright 2014, TH Supcom Corporation";

    /** 提交路径. */
    public static final String SCC_BRANCH = "$URL$";

    /** 提交日期. */
    public static final String SCC_LAST_MODIFICATION_DATE = "$Date$";

    /** 最终修改人员. */
    public static final String SCC_LAST_MODIFIER_NAME = "$Author$";

    /** 最终版本号. */
    public static final String SCC_REVISION = "$Revision$";
}